package car.aistar.service.impl;

import car.aistar.dao.CarCartDao;

import car.aistar.dto.Xxrkanjia;
import car.aistar.entity.CarCart;

import car.aistar.service.CarCartService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CarCart)表服务实现类
 *
 * @author makejava
 * @since 2020-09-30 20:15:11
 */
@Service("carCartService")
public class CarCartServiceImpl implements CarCartService {
    @Resource
    private CarCartDao carCartDao;
    @Autowired
    private XXRxiaoshou xxRxiaoshou;


    @Override
    public List<CarCart> findBySellerId (Long id){
        List<CarCart> carCartList =carCartDao.findAllBysellerId(id);
        return carCartList;
    }

    @Override
    public PageInfo<Xxrkanjia> findByPageKanjia (Long id, String search, Integer pageNow, Integer pageSize){
        return null;
    }

    /**
    *@Author 肖相荣
    *@Description //TODO 销售页面的砍价表分页实现
    *@Date 21:35 2020/10/3
    *@Param [pageNow, pageSize]
    *@return com.github.pagehelper.PageInfo<car.aistar.entity.CarCart>
    **/
    @Override
    public PageInfo<CarCart> findByPage (Long id, Integer pageNow, Integer pageSize){
        PageHelper.startPage(pageNow,pageSize);
        List<CarCart> carCartList = carCartDao.findAllBysellerId(id);
        PageInfo<CarCart> petPageInfo = new PageInfo<>(carCartList);
        return petPageInfo;
    }

    @Override
    public List<CarCart> findAll (){
        return carCartDao.findAll();
    }

    @Override
    public List<CarCart> queryAll(CarCart carCart) {
        return this.carCartDao.queryAll(carCart);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CarCart queryById(Long id) {
        return this.carCartDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<CarCart> queryAllByLimit(int offset, int limit) {
        return this.carCartDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param carCart 实例对象
     * @return 实例对象
     */
    @Override
    public CarCart insert(CarCart carCart) {
        this.carCartDao.insert(carCart);
        return carCart;
    }

    /**
     * 修改数据
     *
     * @param carCart 实例对象
     * @return 实例对象
     */
    @Override
    public CarCart update(CarCart carCart) {
        this.carCartDao.update(carCart);
        return this.queryById(carCart.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.carCartDao.deleteById(id) > 0;
    }
}